﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿﻿require.config({
  urlArgs: "version=20170407",
  paths: {
    'jquery': '/js/packages/jquery-2.14-min',
    'jquery_page':"/js/packages/jquery.twbsPagination",
    'bootstrap': '/bootstrap/js/bootstrap.min',
    'bootstrapdate': '/bootstrap/bootstrap-date/js/bootstrap-datetimepicker.min',
    
  },
  shim: {
    'bootstrap': {
      deps: ['jquery'],
      exports: 'bootstrap'
    },
  	'bootstrapdate':{
  		deps: ['jquery'],
        exports: 'bootstrap'
  	},
  	'jquery_page':{
  		deps: ['jquery'],
        exports: 'bootstrap'
  	}
  }
  
});

require(['jquery','bootstrap','bootstrapdate','jquery_page'], function ($) {
	//$('#search-query').removeAttr("readonly");
	current_depot_id = 1;
	var curr_page = 1;
	var curr_size = 20;
	curr_query_id="";
	//----------------------------------------------
	
	var data_columns = ['id','content','createAt'];
	var action_columns = ['删除'];
	//set_query_type(0);
	set_url('/query/list/all');
	set_data_columns(data_columns);
	set_action_columns(action_columns);
	//set_has_input(true);
	var myfunction = function() {
		$('td>div>span').click(function(){
			//var id = $(this).parent().parent().find('>ul>li>label>input').prop('checked', true);
			if($(this).text()=="保存") {
				save_query(get_curr_span_id($(this)));
			}else if($(this).text()=="删除") {
				set_curr_query_id(get_curr_span_id($(this)));
			}
		});
		
	};
	set_function(myfunction);
	init_page(curr_page,curr_size);
	
	//---------------------------------------------------------
	
	$("#deleteConfirm").click(function(event){
		delete_query(curr_query_id);
	});
	
	function set_curr_query_id(query_id) {
		curr_query_id = query_id.split('-')[2];
		$('#removeModal').modal('show');
	}
	function save_query(query_id) {
		$.post('/query/save',
		{
			'id' : query_id,
		});
		init_page(curr_page,curr_size);
	}
	function delete_query(query_id) {
		//query_id = parseInt(query_id.split('-')[2]);
		console.log(query_id)
		$.ajax({
			type : 'POST',  
			url : '/query/delete', 
			data : {
				'id' : query_id,
			},
	        contentType: "application/x-www-form-urlencoded",  
	        dataType : 'json',  
	        success : function(res) {
			    init_page(curr_page,curr_size);
			}
		});
		
	}

});
